// pages/resert/resert.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    phone:'',
    password:'',
    NewPassword:'',
    ConfirmPassword:''
  },
  bindphone:function(e){
    this.setData({phone:e.detail.value})
  },
  bindps1:function(e){
    this.setData({password:e.detail.value})
  },
  bindps2:function(e){
    this.setData({NewPassword:e.detail.value})
  },
  bindps3:function(e){
    this.setData({ConfirmPassword:e.detail.value})
  },
  resert:function(e){
    if(!this.data.phone){
      wx.showModal({
        title: '',
        content: '手机号不能为空',
        icon:''
      }) 
    }else if(!this.data.password || !this.data.NewPassword || !this.data.ConfirmPassword){
      wx.showModal({
        title: '',
        content: '密码不能为空',
        icon:''
      }) 
    }else if(this.data.password == this.data.NewPassword){
      wx.showModal({
        title: '',
        content: '新密码不能与原密码一致',
        icon:''
      }) 
    }else if (this.data.NewPassword != this.data.ConfirmPassword){
      wx.showModal({
        title: '',
        content: '请重新密码确认',
        icon:''
      }) 
    }else{
      wx.request({
        url: 'http://112.74.78.253/api/resert/',
        data:{phone:this.data.phone, password:this.data.password,NewPassword:this.data.NewPassword},
        method:'GET',
        success:function(res){
          console.log(res)
          if (res.data.status==true){
            wx.showToast({
              title: '重置成功',
              icon:'success',
              success: function () {
                setTimeout(function() {
                  wx.redirectTo({
                    url:'../Login_index/Login_index'
                  })
                }, 2000);
              }
            })
          }else if (!res.data.status){
            wx.showToast({
              title: '账号未注册',
              icon:'error'
            })
          }else{
            wx.showToast({
              title: '账号密码错误',
              icon:'error'
            })
          }
        }
      })
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})